<template>
  <el-dialog :title="dialogProps.title" :visible.sync="dialogProps.visible" width='600px' append-to-body>
      
      <el-form   label-width="140px"  :model='form'  ref='form'  :rules='rules'>
              <el-form-item label="姓名："  prop='name'>
                      <el-input v-model.trim="form.name" placeholder="请输入姓名" ></el-input>
              </el-form-item>
              <el-form-item label="身份证号："  prop='idCode'>
                      <el-input v-model.trim="form.idCode" placeholder="请输入身份证号" ></el-input>
              </el-form-item>
              <el-form-item label="账户名称："  prop='subbranchName'>
                      <el-input v-model.trim="form.subbranchName" placeholder="请输入账户" ></el-input>
              </el-form-item>
              <el-form-item label="账户号码："  prop='bankAccount'>
                      <el-input v-model.trim="form.bankAccount" placeholder="请输入账户" ></el-input>
              </el-form-item>
              <el-form-item label="投资金额（元）："  prop='investmentAmt'>
                      <el-input v-model.trim="form.investmentAmt" placeholder="请输入" ></el-input>
              </el-form-item>
              <el-form-item label="附件资料："  >
                      <el-upload  class='inline-block'
                        
                        :action="actionAddress"
                        :limit='1'
                        :on-success='handleSuccess'
                        :on-exceed='handleExceed'
                        >
                        <el-button   type="primary"  size="small"  >上传</el-button>
                    </el-upload>
              </el-form-item>
      </el-form>
       <div slot="footer" class="dialog-footer">
              <el-button @click="dialogProps.visible = false">取 消</el-button>
              <el-button type="primary" @click="submit('form')">确 定</el-button>
        </div>
  </el-dialog>
</template>

<script charset="utf-8" type="text/javascript">
  import  { saveInvestor }  from  '@/api/professional_work/investor'
export default {
  name: 'add_investor',
  data() {

    return {
      //文件上传请求地址
      actionAddress:process.env.BASE_API+'/op/fileupload/upload_file',

      loading: false,
      //dialogo基本信息  显示隐藏状态  title 
      dialogProps: {
        visible: false,
        action: '',
        title: '新增投资人'
      },
      form:{
        name:'',
        idCode:'',
        subbranchName:'',
        bankAccount:'',
        investmentAmt:'',
        fileCode:'',
        prdObjCode:'',//标的code
      },
      rules:{
        name:[
          {required :true,message:'请输入投资人姓名'}
        ],
        investmentAmt:[
          {required :true,message:'请输入投资金额'}
        ],
      },
      

    }
  },
  created(){
    
    
  },
  methods: {
   
    submit(formName) {

      saveInvestor(this.form).then(res=>{
        this.$message({type:'success',message:res.data.msg})
        this.$emit('save-finished')
        this.dialogProps.visible=false
      }).catch(error=>{
        console.log(error)
      })
      
    },
    //文件上传成功之后的回调  保存文件
    handleSuccess(response, file, fileList){
      // console.log(response)
      // console.log(file)
      this.form.fileCode = file.response.data.code
    },
    handleExceed(files, fileList) {
        this.$message.warning(`超过上传一个文件最大限制！`);
    },
    
  },
  mounted: function() {
    this.$nextTick(() => {
      this.$on('openDialog', function(code) {
        this.dialogProps.visible = true
        this.form.prdObjCode = code
      })
      
    })
  },
  updated(){
    
  },
  components:{
    
  }
}
</script>

<style  scoped>
</style>


